package 面向对象.phone;

public class phoneTest {
    public static void main(String[] args) {
        //创建数组
        Phone[] arr = new Phone[3];

        //创建三个手机对象
        Phone p1 = new Phone("小米", 1999, "蓝色");
        Phone p2 = new Phone("苹果", 8888, "金色");
        Phone p3 = new Phone("华为", 5999, "红色");

        //把手机对象添加到数组当中
        arr[0] = p1;
        arr[1] = p2;
        arr[2] = p3;

        //获取三部手机的总价格
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            //i表示索引  arr[i]表示手机对象
            Phone p = arr[i];
            sum = sum + p.getPrice();
        }

        //求三部手机的平均价格
        int avg = sum / arr.length;//数据能不写死就不写死
        System.out.println("三部手机的平均价格是：" + avg);
    }
}
